import 'dart:convert';

import 'package:card_swiper/card_swiper.dart';
import 'package:cbec_app/components/base/base_badges.dart';
import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/base/image_text_item.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/common/count_down_timer.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/custom_fraction_swiper.dart';
import 'package:cbec_app/components/common/custom_rect_swiper.dart';
import 'package:cbec_app/components/common/recommend.dart';
import 'package:cbec_app/components/popup/receive_coupon_popup.dart';
import 'package:cbec_app/components/popup/select_specifications_popup.dart';
import 'package:cbec_app/components/popup/service_detail_popup.dart';
import 'package:cbec_app/pages/goods/controller/goods_detail_ctr.dart';
import 'package:cbec_app/pages/goods/view/star_text_widget.dart';
import 'package:cbec_app/routes/routes.dart';
import 'package:cbec_app/utils/EventMgr.dart';
import 'package:cbec_app/utils/ThemeConfig.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import '../../../utils/logger.dart';
import '../../classify/binding/brand_detail_binding.dart';
import '../../classify/view/brand_detail.dart';
import '../../my/view/deposit_payment_widget.dart';

///商品详情页
class GoodsDetailPage extends StatelessWidget {
  final String? flag;

  const GoodsDetailPage({super.key, this.flag});

  @override
  Widget build(context) {
    GoodsDetailController controller = Get.find(tag: flag);
    return GetBuilder<GoodsDetailController>(
      tag: flag,
      builder: (controller) {
        if (controller.detail.isEmpty) {
          return const SizedBox();
        }
        return BasePage(
          // refreshController: controller.baseRefreshCtr,
          // onPageRefresh: controller.onPageRefresh,
          // onPageLoading: controller.onPageLoading,
          // enablePullDown: true,
          // enablePullUp: false,
          isShowMenuIcon: false,
          title: '商品详情',
          iconType: IconType.back,
          children: [
            _goodsImgs(context, controller),
            _goodsInfo(controller),
            _shareBarView(controller),
            _goodsEvaluate(controller),
            _brandName(controller),
            Center(
              child: Container(
                  margin: EdgeInsets.only(top: 8.h),
                  padding: EdgeInsets.only(top: 8.h, bottom: 8.h),
                  color: Colors.white,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        '————',
                        style: TextStyle(color: Tools.fromHex('#dbdbdb')),
                      ),
                      const Text('图文详情'),
                      Text(
                        '————',
                        style: TextStyle(color: Tools.fromHex('#dbdbdb')),
                      ),
                    ],
                  )),
            ),
            (controller.consumerNotice['consumerNoticeLocation'] == 0) ? _consumerNotice(controller) : const SizedBox(),
            _goodsIntroduce(controller),
            (controller.consumerNotice['consumerNoticeLocation'] == 1) ? _consumerNotice(controller) : const SizedBox(),

            Recommend(),
            emptyMargin(100.h),
            // Container(
            //   margin: EdgeInsets.only(left: 8.w, right: 8.w),
            //   child: Wrap(
            //       alignment: WrapAlignment.spaceBetween,
            //       runSpacing: 6.w,
            //       children: _createList()),
            // ),
            _bottomOperate(context, controller),
          ],
        );
      },
    );
  }

  ///商品图片
  Widget _goodsImgs(BuildContext context, GoodsDetailController controller) {
    return Container(
        width: 375.w,
        height: 375.w,
        child: FutureBuilder(
          future: Future.wait(controller.goodsImages.map((imageUrl) => precacheImage(imageUrl, context))),
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.done) {
              return Swiper(
                autoplay: true,
                autoplayDisableOnInteraction: true,
                itemBuilder: (context, index) {
                  return BaseImage(url: controller.goodsImages[index], width: 375.w, height: 375.w);
                },
                itemCount: controller.goodsImages.length,
                pagination: controller.goodsImages.length <= 8 ? const SwiperPagination(builder: CustomRectSwiper(activeColor: ThemeConfig.themeColor)) : const SwiperPagination(alignment: Alignment.bottomRight, margin: EdgeInsets.only(right: 20), builder: CustomFractionSwiper(activeColor: ThemeConfig.themeColor)),
              );
            }

            return emptyWidget();
          },
        ));
  }

  ///商品信息
  Widget _goodsInfo(GoodsDetailController controller) {
    return Container(
      margin: const EdgeInsets.only(top: 8, left: 8, right: 8),
      child: Column(
        children: [
          Stack(
            children: [
              getHeaderByGoodsType(controller),
              Positioned(
                bottom: -1,
                left: 0,
                right: 0,
                child: Container(
                  height: 20,
                  decoration: const BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20)),
                  ),
                ),
              )
            ],
          ),
          Container(
            padding: const EdgeInsets.only(left: 10.0, right: 10.0),
            color: Colors.white,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                if (controller.preSaleInfo.isNotEmpty && controller.preSaleInfo['status'] == 2) _preSaleBarView(controller),
                _goodsTag(controller),
                _goodsName(controller),
                _buildPreNotice(controller),
                _selectSpecifications(controller),
                freeTax(controller),
                _goodsService(controller),
                _goodsDelivery(controller),
                _editorMsg(controller),
                _showBookList(controller),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildPreNotice(GoodsDetailController controller) {
    // 0-普通订单 2-特价订单 3-秒杀订单 4-拼团订单 5-预售订单 6-卡券订单 7-充值订单 8-砍价订单 9-新人好礼订单
    bool isCan = (controller.specialInfo.isNotEmpty || controller.seckillInfo.isNotEmpty || controller.bookInfo.isNotEmpty || controller.preSaleInfo.isNotEmpty);
    if (!isCan) {
      return const SizedBox();
    }

    bool isShow = (controller.specialInfo['status'] == 3 || controller.seckillInfo['status'] == 3 || controller.bookInfo['status'] == 3 || controller.preSaleInfo['status'] == 3);
    if (!isShow) {
      return const SizedBox();
    }

    String price = '';
    int timeStamp = 0;
    switch (controller.goodsType) {
      case 2:
        price = '限时秒杀价：¥${controller.specialInfo['priceSpecial'].toStringAsFixed(2)}';
        timeStamp = controller.specialInfo['startTime'] * 1000;
      case 3:
        price = '秒杀价：¥${controller.seckillInfo['priceSeckill'].toStringAsFixed(2)}';
        timeStamp = controller.seckillInfo['startTime'] * 1000;
      case 4:
        // TODO 如果有团长价显示团长价，如果没有，就显示最后一个阶梯的价格
        if (controller.bookInfo['hasSetMasterPrice'] == 1) {
          price = '拼团价：¥${controller.bookInfo['priceBookMaster'].toStringAsFixed(2)}';
        } else {
          List<Map<String, dynamic>> priceList = controller.bookInfo['priceList'];
          Map<dynamic, dynamic> item = priceList.first;
          price = '拼团价：¥${item['priceBook'].toStringAsFixed(2)}';
        }
        timeStamp = controller.bookInfo['startTime'] * 1000;
      case 5:
        // TODO 全款预售 pricePresale ，定金预售
        if (controller.preSaleInfo['presaleType'] == 1) {
          price = '预售价：¥${controller.preSaleInfo['pricePresale'].toStringAsFixed(2)}';
        } else {
          price = '预售价：¥${controller.preSaleInfo['pricePresale'].toStringAsFixed(2)}';
        }
        timeStamp = controller.preSaleInfo['startTime'] * 1000;
      default:
        break;
    }

    return Container(
      padding: EdgeInsets.only(top: 8.h, bottom: 8.h),
      child: Row(
        children: [
          Text(
            '预告',
            style: setTextStyle(14, FontWeight.w400, ThemeConfig.sectionTextColor),
          ),
          const SizedBox(width: 5),
          Text(
            price,
            style: setTextStyle(13, FontWeight.w400, Tools.fromHex('#F83F2D')),
          ),

          // int time = specialInfo['endTime'] * 1000 - DateTime.now().millisecondsSinceEpoch;
          const SizedBox(width: 10),
          Row(
            children: [
              Text(
                '距开始还剩',
                style: setTextStyle(
                  13,
                  FontWeight.w400,
                  Tools.fromHex('#333333'),
                ),
              ),
              const SizedBox(width: 5),
              CountDownTimer(
                timeStamp: timeStamp,
                timeStyle: TimeStyle.hhmmss,
                style: setTextStyle(
                  13,
                  FontWeight.w400,
                  Tools.fromHex('#333333'),
                ),
                callback: () {
                  Get.back();
                },
              ),
            ],
          )
        ],
      ),
    );
  }

  Widget getHeaderByGoodsType(GoodsDetailController controller) {
    // 0-普通订单 2-特价订单 3-秒杀订单 4-拼团订单 5-预售订单 6-卡券订单 7-充值订单 8-砍价订单 9-新人好礼订单

    print('getHeaderByGoodsType ==== ${controller.goodsType}');

    switch (controller.goodsType) {
      case 0:
        return _commonPriceWidget(controller);
      case 2:
        return controller.specialInfo['status'] == 3 ? _commonPriceWidget(controller) : _specialPriceWidget(controller);
      case 3:
        return controller.seckillInfo['status'] == 3 ? _commonPriceWidget(controller) : _secPriceWidget(controller);
      case 4:
        return controller.bookInfo['status'] == 3 ? _commonPriceWidget(controller) : _groupBuyPriceWidget(controller);
      case 5:
        return controller.preSaleInfo['status'] == 3 ? _commonPriceWidget(controller) : _prePriceWidget(controller);
      case 6:
        return _commonPriceWidget(controller);
      case 7:
        return _commonPriceWidget(controller);
      case 8:
        return _hagglePriceWidget(controller);
      case 9:
        return _newUserPriceWidget(controller);
      default:
        return _commonPriceWidget(controller);
    }
  }

  Widget freeTax(GoodsDetailController controller) {
    return (controller.detail['commodityType'] == 1)
        ? SizedBox(
            child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
                child: Row(
                  children: [
                    Text(
                      '税费',
                      style: setTextStyle(14, FontWeight.w400, ThemeConfig.sectionTextColor),
                    ),
                    const SizedBox(width: 10),
                    Expanded(
                      child: Text(
                        '已含税',
                        style: setTextStyle(13, FontWeight.w400, ThemeConfig.mainTextColor),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ))
        : const SizedBox();
  }

  Widget _editorMsg(GoodsDetailController controller) {
    return (controller.detail['editorMsg'] != null && controller.detail['editorMsg'].isNotEmpty)
        ? SizedBox(
            child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                height: 1, // 分割线高度
                color: Colors.grey[300], // 分割线颜色
              ),
              Container(
                margin: const EdgeInsets.symmetric(vertical: 10.0),
                child: Row(
                  children: [
                    Text(
                      '小编寄语：',
                      style: setTextStyle(14, FontWeight.w400, ThemeConfig.sectionTextColor),
                    ),
                    Expanded(
                      child: Text(
                        '${controller.detail['editorMsg']}',
                        style: setTextStyle(13, FontWeight.w400, ThemeConfig.mainTextColor),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ))
        : const SizedBox();
  }

  /// 预付款，定金展示样式
  Widget _preSaleBarView(GoodsDetailController controller) {
    return Tools.isActivityEnded(controller.preSaleInfo['endTime'])
        ? const SizedBox()
        : DepositPaymentWidget(
            prePayEnd: controller.preSaleInfo['prePayEnd'],
            finalPayEnd: controller.preSaleInfo['finalPayEnd'],
            callBack: () {
              // 显示一个弹窗
              controller.showPreSaleRulerPopop();
            },
          );
  }

  ///商品标签
  Widget _goodsTag(GoodsDetailController controller) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Visibility(
          visible: controller.tags.isNotEmpty,
          child: Container(
            child: Wrap(
              runSpacing: 8.w,
              children: controller.tags
                  .map(
                    (text) => goodsDetailTypeTag(text, margin: EdgeInsets.only(right: 8.w)),
                  )
                  .toList(),
            ),
          ),
        ),
        Visibility(
          visible: controller.isShowCouponBtn,
          child: Container(
            margin: const EdgeInsets.only(right: 10),
            child: BaseInteractive(
              childWidget: Container(
                width: 46.w,
                height: 21.h,
                alignment: Alignment.center,
                decoration: const BoxDecoration(color: ThemeConfig.themeColor, borderRadius: BorderRadius.all(Radius.circular(20))),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(
                      '领券',
                      style: setTextStyle(11, FontWeight.w500, Colors.white),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(left: 4),
                      child: BaseImage(url: 'arrow_right.png', width: 14, height: 14),
                    )
                  ],
                ),
              ),
              onClick: () {
                showReceiveCouponPopup(
                  info: controller.preferentialInfo,
                  onReceiveCoupon: (couponId) {
                    controller.receiveCoupon(couponId);
                  },
                  onReceiveRedPack: (redPacketId) {
                    controller.receiveRedPack(redPacketId);
                  },
                );
              },
            ),
          ),
        )
      ],
    );
  }

  ///商品名称
  Widget _goodsName(GoodsDetailController controller) {
    return Padding(
      padding: EdgeInsets.only(top: 10.h),
      child: Text.rich(TextSpan(children: [WidgetSpan(child: goodsTypeTag(getGoodsTypeName(controller.detail['commodityType'] ?? 0), margin: EdgeInsets.only(right: 5))), TextSpan(text: controller.detail['commodityName'] ?? '', style: setTextStyle(14, FontWeight.w500, ThemeConfig.mainTextColor))])),
    );
  }

  ///文本宽度
  double get textWidth => 267.7.w;

  ///选择规格
  Widget _selectSpecifications(GoodsDetailController controller) {
    return Visibility(
      visible: controller.detail['spuSpecJsonBody'] != null && controller.isCanShowSpecifications,
      child: Padding(
        padding: EdgeInsets.only(top: 10.h),
        child: Row(
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: EdgeInsets.only(top: 8.h),
              child: Text(
                '选择',
                style: setTextStyle(13, FontWeight.w400, ThemeConfig.sectionTextColor),
              ),
            ),
            Expanded(
              child: Container(
                margin: EdgeInsets.only(left: 10.w),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        Row(
                          children: controller.showSkus
                              .map((item) => Row(
                                    children: [
                                      BaseImage(url: item['image'], width: 32.w, height: 32.w),
                                      SizedBox(
                                        width: 8.w,
                                      ),
                                    ],
                                  ))
                              .toList(),
                        ),
                        Visibility(
                          visible: controller.skus.isNotEmpty,
                          child: Container(
                            padding: const EdgeInsets.only(top: 5, bottom: 5, left: 10, right: 10),
                            margin: EdgeInsets.only(left: 2.w),
                            alignment: Alignment.center,
                            decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(2)), color: Color(0xfff8f8f8)),
                            child: Text(
                              '共${controller.skus.length}款',
                              style: setTextStyle(13, FontWeight.w400, ThemeConfig.sectionTextColor),
                            ),
                          ),
                        )
                      ],
                    ),
                    SizedBox(
                      width: double.infinity,
                      child: GestureDetector(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Container(
                              padding: const EdgeInsets.symmetric(vertical: 8),
                              child: Text(
                                '${controller.detail['spuSpecJsonBody']}',
                                style: setTextStyle(13, FontWeight.w400, ThemeConfig.mainTextColor),
                              ),
                            ),
                            Icon(
                              Icons.navigate_next,
                              color: Tools.fromHex('#999999'),
                            )
                          ],
                        ),
                        onTap: () {
                          print('isCanShowSpecifications ===== ${controller.isCanShowSpecifications}');
                          controller.isAutoJump = true;
                          showSelectSpecificationsPopup(
                              mainImg: controller.isCanShowSpecifications ? controller.detail['imageList'].first : null,
                              goodsInfo: controller.detail,
                              goodsType: controller.goodsType,
                              goodsNum: controller.selectedGoodsNum,
                              selectedIndex: controller.selectedIndex,
                              onConfirm: (specIndex, goodsNum, groupIndex) {
                                controller.joinSku(specIndex, goodsNum);
                              },
                              onSelectSku: (id) {
                                print('onSelectSku === $id');
                                controller.onSelectSku(id);
                              },
                              specValue: '${controller.detail['spuSpecJsonBody']}');
                        },
                      ),
                    )
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  ///配送
  Widget _goodsDelivery(GoodsDetailController controller) {
    return Row(
      mainAxisSize: MainAxisSize.max,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Padding(
          padding: const EdgeInsets.only(top: 2),
          child: Text(
            '配送',
            style: setTextStyle(13, FontWeight.w400, ThemeConfig.sectionTextColor),
          ),
        ),
        Expanded(
          child: Container(
            margin: EdgeInsets.only(left: 10.w),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                BaseInteractive(
                  childWidget: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      SizedBox(
                        width: (ScreenUtil().screenWidth - 40) * 0.8,
                        child: Text(
                          controller.address != '' ? controller.address : '请添加收货地址',
                          style: setTextStyle(13, FontWeight.w400, ThemeConfig.mainTextColor),
                        ),
                      ),
                      Icon(Icons.navigate_next, color: Tools.fromHex('#999999')),
                    ],
                  ),
                  onClick: () {
                    Get.toNamed('${Routes.address}?isSelect=true');
                  },
                ),
                SizedBox(
                  width: textWidth,
                  child: Text(
                    '${controller.detail['shippingContent']}',
                    style: setTextStyle(13, FontWeight.bold, ThemeConfig.mainTextColor),
                  ),
                ),
                const SizedBox(height: 10),
              ],
            ),
          ),
        )
      ],
    );
  }

  ///获取配送方式
  String getDeliveryType(GoodsDetailController controller) {
    String type = controller.detail['deliveryType'].toString();
    switch (type) {
      case '1':
        return '自提';
      case '2':
        return '快递或自提';
      case '0':
      default:
        return '快递';
    }
  }

  ///服务
  Widget _goodsService(GoodsDetailController controller) {
    if (controller.serviceList.isEmpty) {
      return const SizedBox();
    }
    return Container(
      margin: EdgeInsets.only(top: 8.h, left: 0, right: 0, bottom: 8.h),
      child: Column(
        children: [
          Container(height: 1, color: Colors.grey[300]),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                '服务',
                style: setTextStyle(13, FontWeight.w400, ThemeConfig.sectionTextColor),
              ),
              Expanded(
                child: Container(
                    margin: EdgeInsets.only(left: 10.h, top: 10, bottom: 10),
                    child: BaseInteractive(
                      childWidget: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        // crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(
                            controller.serviceList.isNotEmpty ? controller.serviceList[0]['serviceName'] : '暂无服务',
                            style: setTextStyle(13, FontWeight.w400, ThemeConfig.mainTextColor),
                          ),
                          Icon(Icons.navigate_next, color: Tools.fromHex('#999999')),
                        ],
                      ),
                      onClick: () {
                        if (controller.serviceList.isEmpty) {
                          return;
                        }
                        showServiceDetailPopup(controller.serviceList);
                      },
                    )),
              )
            ],
          ),
          Container(height: 1, color: Colors.grey[300]),
        ],
      ),
    );
  }

  ///运费
  Widget _goodsFreight(GoodsDetailController controller) {
    return Container(
      margin: EdgeInsets.only(top: 8.h, left: 0, right: 0, bottom: 8.h),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            '运费',
            style: setTextStyle(13, FontWeight.w400, ThemeConfig.sectionTextColor),
          ),
          Container(
            margin: EdgeInsets.only(left: 10.h),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Container(
                  width: textWidth,
                  child: Text(
                    controller.detail['priceExpressString'] ?? '暂无运费说明',
                    style: setTextStyle(13, FontWeight.w400, ThemeConfig.mainTextColor),
                  ),
                ),
                Icon(Icons.navigate_next)
              ],
            ),
          )
        ],
      ),
    );
  }

  Widget _showBookList(GoodsDetailController controller) {
    List bookList = (controller.detail['showBookList'] is List && (controller.detail['showBookList'] as List).isNotEmpty) ? controller.detail['showBookList'] : [];
    bool isShowWidget = bookList.isNotEmpty;
    return isShowWidget
        ? Padding(
            padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
            child: ListView.builder(
                itemCount: bookList.length,
                shrinkWrap: true, // 关键属性，高度自适应
                physics: const NeverScrollableScrollPhysics(), // 禁止内部滚动
                itemBuilder: (content, index) {
                  Map<String, dynamic> item = bookList[index];
                  return Container(
                    margin: EdgeInsets.symmetric(vertical: 5),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            ClipOval(
                              child: BaseImage(
                                url: item['avatar'],
                                height: 40,
                                width: 40,
                              ),
                            ),
                            const SizedBox(width: 10),
                            Text(
                              item['nickname'],
                              style: TextStyle(fontSize: 14, color: Tools.fromHex('#666666')),
                            )
                          ],
                        ),
                        Row(
                          children: [
                            Column(
                              children: [
                                Text(
                                  '拼单即将结束',
                                  style: TextStyle(
                                    fontSize: 14,
                                    color: Tools.fromHex('#484848'),
                                  ),
                                ),
                                CountDownTimer(
                                  timeStyle: TimeStyle.hhmmss,
                                  timeStamp: item['ldTimeStamp'] != null ? item['ldTimeStamp'] * 1000 : 0,
                                  countDownStyle: CountDownStyle.pureText,
                                  style: setTextStyle(
                                    14,
                                    FontWeight.w700,
                                    Tools.fromHex('#f0857a'),
                                  ),
                                  callback: () {
                                    logger.d('结束');
                                  },
                                )
                              ],
                            ),
                            const SizedBox(width: 20),
                            InkWell(
                              onTap: () {
                                var bookId = item['bookId'];
                                Get.toNamed(Routes.invitedFriends, arguments: bookId);
                              },
                              child: Container(
                                decoration: BoxDecoration(
                                  color: Tools.fromHex('#ec4c39'),
                                  borderRadius: BorderRadius.circular(8),
                                ),
                                child: Padding(
                                  padding: const EdgeInsets.fromLTRB(10, 5, 10, 5),
                                  child: Text(
                                    '参与拼团',
                                    style: TextStyle(color: Tools.fromHex('#ffffff'), fontSize: 10),
                                  ),
                                ),
                              ),
                            )
                          ],
                        )
                      ],
                    ),
                  );
                }),
          )
        : const SizedBox();
  }

  Widget _shareBarView(GoodsDetailController controller) {
    return Container(
      color: Tools.fromHex('#F4EAE9'),
      margin: const EdgeInsets.only(left: 8, right: 8, top: 8, bottom: 0),
      padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
      child: Row(
        children: [
          StarTextWidget(
            text: '分享',
            textStyle: TextStyle(
              fontSize: 12,
              color: Tools.fromHex('#e9513a'),
            ),
            borderColor: Tools.fromHex('#e9513a'),
          ),
          const SizedBox(width: 10),
          const Text('发给好友看看吧～'),
          const Spacer(),
          BaseInteractive(
            childWidget: Row(
              children: [
                Text('立即分享', style: setTextStyle(14, FontWeight.w400, ThemeConfig.themeColor)),
                const Icon(Icons.navigate_next, color: ThemeConfig.themeColor),
              ],
            ),
            onClick: () {
              controller.shareMiniProgram(controller.detail['commodityId'], controller.goodsImages.first);
            },
          )
        ],
      ),
    );
  }

  ///评价
  Widget _goodsEvaluate(GoodsDetailController controller) {
    return GestureDetector(
      onTap: () {
        Get.toNamed(Routes.commentList, arguments: {
          'id': controller.goodsId,
        });
        //评价列表模块
      },
      child: Container(
        margin: EdgeInsets.only(left: 8.w, right: 8.w, top: 8.h),
        decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(8)), color: Colors.white),
        child: Container(
          margin: EdgeInsets.symmetric(vertical: 15.w, horizontal: 10.w),
          child: Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Text(
                        '商品评价',
                        style: setTextStyle(16, FontWeight.w700, ThemeConfig.mainTextColor),
                      ),
                      Padding(
                        padding: EdgeInsets.only(left: 4.w),
                        child: Text(
                          '(${controller.commentList.length})',
                          style: setTextStyle(12, FontWeight.w400, ThemeConfig.sectionTextColor),
                        ),
                      )
                    ],
                  ),
                  Text(
                    '好评率${controller.detail['positiveReviewRate']}%',
                    style: setTextStyle(12, FontWeight.w400, ThemeConfig.mainTextColor),
                  )
                ],
              ),
              // _evaluateTag(),
              // _evaluateDetail(),
            ],
          ),
        ),
      ),
    );
  }

  ///品牌名称
  Widget _brandName(GoodsDetailController controller) {
    return BaseInteractive(
      onClick: () {
        String id = controller.detail['brandId'];
        Get.to(
          () => BrandDetail(flag: id), // 使用函数懒加载页面实例
          routeName: '${Routes.brandDtail}?unique=${DateTime.now().millisecondsSinceEpoch}',
          arguments: {"id": id}, // 传递其它参数
          binding: BrandDetailBinding(flag: id), // 将 tag 参数传递给绑定类
        );
      },
      childWidget: Container(
        margin: EdgeInsets.only(top: 8.h, left: 8.w, right: 8.w),
        decoration: const BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(8)),
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [Color(0xffFFF2FB), Color(0xffFEFCFD)],
          ),
        ),
        child: Container(
          margin: EdgeInsets.only(left: 10.w, top: 10.h, bottom: 10.h, right: 10.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                children: [
                  BaseImage(
                    url: controller.detail['brandImage'] ?? '',
                    width: 60.w,
                    height: 60.w,
                    borderRadius: BorderRadius.all(Radius.circular(60.w)),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 8.w),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          controller.detail['brandName'] ?? '',
                          style: setTextStyle(14, FontWeight.w500, ThemeConfig.mainTextColor),
                        ),
                        Row(
                          children: [
                            Text(
                              '商品数量',
                              style: setTextStyle(12, FontWeight.w400, ThemeConfig.sectionTextColor),
                            ),
                            Text(
                              controller.detail['brandGoodsNumber'].toString(),
                              style: setTextStyle(12, FontWeight.w400, ThemeConfig.boldTextColor),
                            )
                          ],
                        )
                      ],
                    ),
                  )
                ],
              ),
              Icon(Icons.navigate_next, color: Tools.fromHex('#999999'))
            ],
          ),
        ),
      ),
    );
  }

  ///商品介绍
  Widget _goodsIntroduce(GoodsDetailController controller) {
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 15),
      color: Colors.white,
      child: HtmlWidget(controller.goodsRichDetail),
    );
  }

  Widget _consumerNotice(GoodsDetailController controller) {
    return controller.consumerNotice.isNotEmpty
        ? Visibility(
            visible: controller.consumerNotice['consumerNoticeStatus'],
            child: Image.network(controller.consumerNotice['consumerNoticeImage']),
          )
        : const SizedBox();
  }

  ///底部操作栏
  Widget _bottomOperate(BuildContext context, GoodsDetailController controller) {
    var bottomHeight = MediaQuery.of(context).padding.bottom;
    return Positioned(
        key: GlobalKey(debugLabel: 'Positioned'),
        left: 0,
        bottom: 0,
        child: Container(
          width: 375.w,
          padding: EdgeInsets.only(top: 10.h, bottom: bottomHeight > 0 ? bottomHeight : 10.h),
          color: Colors.white,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Visibility(
                visible: controller.goodsType == 6 ? false : true,
                child: Container(
                  margin: EdgeInsets.only(left: 9.w),
                  child: Row(
                    children: [
                      _setBtnStyle(
                        controller,
                        'customer.png',
                        '客服',
                        onClick: () {
                          Get.toNamed(Routes.serviceSupportPage);
                        },
                      ),
                      SizedBox(
                        width: 8.w,
                      ),
                      _shopCarBadges(controller),
                      SizedBox(
                        width: 8.w,
                      ),
                      _setBtnStyle(controller, controller.collectIcon, '收藏'),
                      SizedBox(width: 8.w),
                      _setBtnStyle(
                        controller,
                        'fenxiang.png',
                        '分享',
                        onClick: () {
                          controller.shareMiniProgram(controller.detail['commodityId'], controller.goodsImages.first);
                        },
                      ),
                    ],
                  ),
                ),
              ),
              Expanded(
                child: Container(
                  margin: EdgeInsets.only(left: 8.w, right: 8.w),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    mainAxisSize: MainAxisSize.max,
                    children: [_bottomBuyStyle0(controller)],
                  ),
                ),
              )
            ],
          ),
        ));
  }

  ///设置按钮样式
  Widget _setBtnStyle(GoodsDetailController controller, String url, String text, {void Function()? onClick}) {
    return ImageTextItem(
      url: url,
      width: 20.w,
      height: 20.w,
      text: text,
      style: setTextStyle(10, FontWeight.w400, ThemeConfig.boldTextColor),
      marginTop: 3,
      onTap: () {
        //点击收藏
        if (url.startsWith('collect')) {
          controller.toggleCollect();
          _setBtnStyle(controller, url, text);
        } else {
          if (onClick != null) {
            onClick();
          }
        }
      },
    );
  }

  ///购物车角标
  Widget _shopCarBadges(GoodsDetailController controller) {
    return BaseBadges(
      num: controller.carGoodsNum,
      translateX: 0,
      translateY: -5,
      badgesStyle: BadgesStyle.hasBorder,
      child: _setBtnStyle(
        controller,
        'bags_default.png',
        '购物车',
        onClick: () {
          Get.until((route) => Get.currentRoute == Routes.main);
          EventMgr.send(EventType.exchangeNav, 'bags');
        },
      ),
    );
  }

  /// 不同类型的商品 样式展示

  /// 特价
  Widget _specialPriceWidget(GoodsDetailController controller) {
    return Container(
      height: 80,
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20), bottomLeft: Radius.circular(0), bottomRight: Radius.circular(0)),
        gradient: LinearGradient(colors: [Tools.fromHex('#EB5D37'), Tools.fromHex('#EE254F')], begin: Alignment.centerLeft, end: Alignment.centerRight),
      ),
      child: Container(
        child: Padding(
          padding: const EdgeInsets.only(left: 20, right: 20),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            mainAxisSize: MainAxisSize.max,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      const Text(
                        '¥',
                        style: TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.w700),
                      ),
                      const SizedBox(
                        width: 5,
                      ),
                      Text(
                        controller.specialInfo['priceSpecial'].toString(),
                        style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w700),
                      ),
                      const SizedBox(
                        width: 5,
                      ),
                      Text(
                        controller.priceInfo['price'].toString(),
                        style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w300, decoration: TextDecoration.lineThrough, decorationThickness: 1, decorationColor: Colors.white),
                      ),
                    ],
                  ),
                  Visibility(
                    visible: controller.specialInfo['status'] != 1,
                    child: Row(
                      children: [
                        Text(
                          '距结束 ',
                          style: setTextStyle(14, FontWeight.w700, Colors.white),
                        ),
                        CountDownTimer(
                          timeStyle: TimeStyle.ddhhmmss,
                          timeStamp: controller.specialInfo['endTime'] != null ? controller.specialInfo['endTime'] * 1000 : 0,
                          countDownStyle: CountDownStyle.pureText,
                          style: setTextStyle(14, FontWeight.w700, Colors.white),
                          callback: () {
                            logger.d('结束');
                          },
                        )
                      ],
                    ),
                  )
                ],
              ),
              Column(
                children: [
                  const Text(
                    '限时特卖',
                    style: TextStyle(fontFamily: 'youshebiaotihei', fontSize: 20, color: Colors.white),
                  ),
                  Visibility(
                    visible: controller.specialInfo['type'] == 1,
                    child: const Text('活动待开始',
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 14,
                        )),
                  )
                ],
              )
            ],
          ),
        ),
      ),
    );
  }

  /// 秒杀
  Widget _secPriceWidget(GoodsDetailController controller) {
    return Container(
      height: 80,
      margin: EdgeInsets.only(top: 0.h),
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20), bottomLeft: Radius.circular(0), bottomRight: Radius.circular(0)),
        gradient: LinearGradient(colors: [Tools.fromHex('#FD423B'), Tools.fromHex('#FE332C')], begin: Alignment.centerLeft, end: Alignment.centerRight),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 0, left: 10, right: 10, bottom: 20),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Image.asset(
              'assets/images/bd_seckill.png',
              width: 70,
              height: 14,
            ),
            const SizedBox(
              width: 5,
            ),
            const Text(
              '¥',
              style: TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.w700),
            ),
            const SizedBox(
              width: 5,
            ),
            Text(
              controller.seckillInfo['priceSeckill'].toString(),
              style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w700),
            ),
            const SizedBox(
              width: 5,
            ),
            Text(
              controller.priceInfo['price'].toString(),
              style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w300, decoration: TextDecoration.lineThrough, decorationThickness: 1, decorationColor: Colors.white),
            ),
            const Spacer(),
            if (controller.seckillInfo['status'] == 2) ...[
              // 进行中
              Row(
                children: [
                  Text(
                    '还剩 ',
                    style: setTextStyle(14, FontWeight.w700, Colors.white),
                  ),
                  CountDownTimer(
                    timeStyle: TimeStyle.ddhhmmss,
                    timeStamp: controller.seckillInfo['endTime'] != null ? controller.seckillInfo['endTime'] * 1000 : 0,
                    countDownStyle: CountDownStyle.pureText,
                    style: setTextStyle(14, FontWeight.w700, Colors.white),
                    callback: () {
                      logger.d('结束');
                    },
                  )
                ],
              )
            ] else ...[
              // 待开始
              Row(
                children: [
                  Text(
                    '活动待开始',
                    style: setTextStyle(14, FontWeight.w700, Colors.white),
                  ),
                ],
              ),
            ],
          ],
        ),
      ),
    );
  }

  // 砍价
  Widget _hagglePriceWidget(GoodsDetailController controller) {
    return Container(
      height: 80,
      margin: EdgeInsets.only(top: 10.h),
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20), bottomLeft: Radius.circular(0), bottomRight: Radius.circular(0)),
        gradient: LinearGradient(colors: [Tools.fromHex('#FD423B'), Tools.fromHex('#FE332C')], begin: Alignment.centerLeft, end: Alignment.centerRight),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 20),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            const Text('砍价到手价',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 14,
                )),
            const SizedBox(
              width: 5,
            ),
            const Text(
              '¥',
              style: TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.w700),
            ),
            const SizedBox(
              width: 5,
            ),
            Text(
              controller.haggleInfo['priceHaggle'].toString(),
              style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w700),
            ),
            const SizedBox(
              width: 5,
            ),
            Text(
              controller.priceInfo['price'].toString(),
              style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w300, decoration: TextDecoration.lineThrough, decorationThickness: 1, decorationColor: Colors.white),
            ),
            const Spacer(),
            if (controller.haggleInfo['status'] == 2) ...[
              Row(
                children: [
                  Text(
                    '还剩 ',
                    style: setTextStyle(14, FontWeight.w700, Colors.white),
                  ),
                  CountDownTimer(
                    timeStyle: TimeStyle.ddhhmmss,
                    timeStamp: controller.haggleInfo['endTime'] != null ? controller.haggleInfo['endTime'] * 1000 : 0,
                    countDownStyle: CountDownStyle.pureText,
                    style: setTextStyle(14, FontWeight.w700, Colors.white),
                    callback: () {
                      logger.d('结束');
                    },
                  )
                ],
              )
            ] else ...[
              Row(
                children: [
                  Text(
                    '活动待开始',
                    style: setTextStyle(14, FontWeight.w700, Colors.white),
                  ),
                ],
              ),
            ],
          ],
        ),
      ),
    );
  }

  /// 预售
  Widget _prePriceWidget(GoodsDetailController controller) {
    return Container(
      height: 80,
      margin: EdgeInsets.only(top: 10.h),
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20), bottomLeft: Radius.circular(0), bottomRight: Radius.circular(0)),
        gradient: LinearGradient(colors: [Tools.fromHex('#F96410'), Tools.fromHex('#FBAD3F')], begin: Alignment.centerLeft, end: Alignment.centerRight),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 20),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            const Text(
              '预售抢购',
              style: TextStyle(fontFamily: 'youshebiaotihei', fontSize: 20, color: Colors.white),
            ),
            const SizedBox(
              width: 5,
            ),
            const Text(
              '¥',
              style: TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.w700),
            ),
            const SizedBox(
              width: 5,
            ),
            Text(
              controller.preSaleInfo['pricePresale'].toString(),
              style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w700),
            ),
            const SizedBox(
              width: 5,
            ),
            const Spacer(),
            if (controller.preSaleInfo['status'] == 2) ...[
              Row(
                children: [
                  Text(
                    '预售还剩 ',
                    style: setTextStyle(14, FontWeight.w700, Colors.white),
                  ),
                  CountDownTimer(
                    timeStyle: TimeStyle.ddhhmmss,
                    timeStamp: controller.preSaleInfo['endTime'] != null ? controller.preSaleInfo['endTime'] * 1000 : 0,
                    countDownStyle: CountDownStyle.pureText,
                    style: setTextStyle(14, FontWeight.w700, Colors.white),
                    callback: () {
                      logger.d('结束');
                    },
                  )
                ],
              )
            ] else ...[
              Row(
                children: [
                  Text(
                    '活动待开始',
                    style: setTextStyle(14, FontWeight.w700, Colors.white),
                  ),
                ],
              ),
            ],
          ],
        ),
      ),
    );
  }

  /// 新人好礼
  Widget _newUserPriceWidget(GoodsDetailController controller) {
    return Container(
      height: 80,
      margin: EdgeInsets.only(top: 10.h),
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20), bottomLeft: Radius.circular(0), bottomRight: Radius.circular(0)),
        gradient: LinearGradient(colors: [Tools.fromHex('#FD423B'), Tools.fromHex('#FE332C')], begin: Alignment.centerLeft, end: Alignment.centerRight),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 20),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            const Text(
              '新人到手价',
              style: TextStyle(
                color: Colors.white,
                fontSize: 14,
              ),
            ),
            const SizedBox(
              width: 5,
            ),
            const Text(
              '¥',
              style: TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.w700),
            ),
            const SizedBox(
              width: 5,
            ),
            Text(
              controller.newUserInfo['priceNewUser'].toString(),
              style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w700),
            ),
            const SizedBox(
              width: 5,
            ),
            const Spacer(),
            Row(
              children: [
                Text(
                  '还剩 ',
                  style: setTextStyle(14, FontWeight.w700, Colors.white),
                ),
                CountDownTimer(
                  timeStyle: TimeStyle.ddhhmmss,
                  timeStamp: controller.newUserInfo['endTime'] != null ? controller.newUserInfo['endTime'] * 1000 : 0,
                  countDownStyle: CountDownStyle.pureText,
                  style: setTextStyle(14, FontWeight.w700, Colors.white),
                  callback: () {
                    logger.d('结束');
                  },
                )
              ],
            )
          ],
        ),
      ),
    );
  }

  /// 拼团
  Widget _groupBuyPriceWidget(GoodsDetailController controller) {
    return SizedBox(
        height: 80,
        child: Stack(
          children: [
            Image.asset(
              'assets/images/bd_pingtuan.png',
              width: double.infinity,
              fit: BoxFit.cover,
            ),
            Padding(
              padding: const EdgeInsets.only(top: 10, left: 20, right: 20),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                mainAxisSize: MainAxisSize.max,
                children: [
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          const Text(
                            '¥',
                            style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w700),
                          ),
                          Text(
                            controller.bookInfo['price'].toString().split(',')[0],
                            style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w700),
                          ),
                          const SizedBox(
                            width: 5,
                          ),
                          if (controller.bookInfo['priceBookMaster'] > 0) ...[
                            Text(
                              '团长价：¥${controller.bookInfo['priceBookMaster'].toString()}',
                              style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w300),
                            ),
                          ] else ...[
                            Text(
                              controller.priceInfo['price'].toString(),
                              style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w300, decoration: TextDecoration.lineThrough, decorationThickness: 1, decorationColor: Colors.white),
                            ),
                          ],
                        ],
                      ),
                      if (controller.bookInfo['status'] == 2) ...[
                        Visibility(
                          visible: controller.bookInfo['status'] != 1,
                          child: Row(
                            children: [
                              Text(
                                '距结束 ',
                                style: setTextStyle(14, FontWeight.w700, Colors.white),
                              ),
                              CountDownTimer(
                                timeStyle: TimeStyle.ddhhmmss,
                                timeStamp: controller.bookInfo['endTime'] != null ? controller.bookInfo['endTime'] * 1000 : 0,
                                countDownStyle: CountDownStyle.pureText,
                                style: setTextStyle(14, FontWeight.w700, Colors.white),
                                callback: () {
                                  logger.d('结束');
                                },
                              )
                            ],
                          ),
                        )
                      ] else ...[
                        Text(
                          '活动待开始',
                          style: setTextStyle(14, FontWeight.w700, Colors.white),
                        ),
                      ],
                    ],
                  ),
                  Column(
                    children: [
                      Text(
                        '限时火拼',
                        style: TextStyle(fontFamily: 'youshebiaotihei', fontSize: 20, color: Tools.fromHex('#87480B')),
                      ),
                      Visibility(
                        visible: controller.bookInfo['status'] == 1,
                        child: const Text('待开始',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 14,
                            )),
                      )
                    ],
                  )
                ],
              ),
            ),
          ],
        ));
  }

  // 普通商品
  Widget _commonPriceWidget(GoodsDetailController controller) {
    return Container(
      height: 80,
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20), bottomLeft: Radius.circular(0), bottomRight: Radius.circular(0)),
        gradient: LinearGradient(colors: [Tools.fromHex('#FD423B'), Tools.fromHex('#FE332C')], begin: Alignment.centerLeft, end: Alignment.centerRight),
      ),
      child: Container(
        padding: const EdgeInsets.only(left: 10, right: 10),
        margin: const EdgeInsets.only(bottom: 20),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            const Text(
              '¥',
              style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.normal),
            ),
            const SizedBox(
              width: 5,
            ),
            Text(
              controller.priceInfo['price'].toString(),
              style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w700),
            ),
            const SizedBox(
              width: 5,
            ),
            Stack(
              children: [
                Text(
                  '¥${controller.priceInfo['priceMarket'].toString()}',
                  style: const TextStyle(
                    color: Colors.white,
                    fontSize: 10,
                    fontWeight: FontWeight.w300,
                  ),
                ),
                Positioned(top: 6, child: Container(width: 50, height: 1, color: Colors.white))
              ],
            )
          ],
        ),
      ),
    );
  }

  Widget _bottomBuyStyle0(GoodsDetailController controller) {
    print('_bottomBuyStyle ==== ${controller.goodsType}');

    ///0-普通订单 2-特价订单 3-秒杀订单 4-拼团订单 5-预售订单 6-卡券订单 7-充值订单 8-砍价订单 9-新人好礼订单
    switch (controller.goodsType) {
      case 0:
        return _bottomBuyStyleCommon(controller);
      case 1:
        return _bottomBuyStyleCommon(controller);
      case 2:
        return _bottomBuyStyleCommon(controller);
      case 3:
        return controller.seckillInfo['status'] == 3 ? _bottomBuyStyleCommon(controller) : _bottomBuyStyleSeckillInfo(controller);
      case 4:
        return controller.bookInfo['status'] == 3 ? _bottomBuyStyleCommon(controller) : _bottomBuyStyleGroup(controller);
      case 5:
        return controller.preSaleInfo['status'] == 3 ? _bottomBuyStyleCommon(controller) : _bottomBuyStylePreSale(controller);
      case 6:
        return _bottomBuyStyleCardCoupon(controller);
      case 7:
        return _bottomBuyStyleCommon(controller);
      case 8:
        return _bottomBuyStyleHaggle(controller);
      case 9:
        return _bottomBuyStyleCommon(controller);
      default:
        return _bottomBuyStyleCommon(controller);
    }
  }

  // 普通商品 特价商品 新人专区
  Widget _bottomBuyStyleCommon(GoodsDetailController controller) {
    return Expanded(
      child: SizedBox(
        child: Row(
          children: [
            Expanded(
              child: ElevatedButton(
                onPressed: () {
                  controller.addCar();
                },
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
                  backgroundColor: Tools.fromHex('#F7CA36'), // 去除默认背景色
                  shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.only(topLeft: Radius.circular(30), bottomLeft: Radius.circular(30)),
                  ), // 按钮圆角
                ),
                child: const Text(
                  '加入购物车',
                  style: TextStyle(color: Colors.white, fontSize: 15), // 按钮文本样式
                ),
              ),
            ),
            Expanded(
              child: ElevatedButton(
                onPressed: () {
                  controller.jumpFillOrder();
                },
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
                  backgroundColor: Tools.fromHex('#F83F2D'), // 去除默认背景色
                  shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.only(
                      topRight: Radius.circular(30),
                      bottomRight: Radius.circular(30),
                    ),
                  ),
                ),
                child: const Text(
                  '立即购买',
                  style: TextStyle(color: Colors.white, fontSize: 15), // 按钮文本样式
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 拼团
  Widget _bottomBuyStyleGroup(GoodsDetailController controller) {
    return SizedBox(
      child: Row(
        children: [
          // 左边按钮
          BaseInteractive(
            childWidget: Container(
              // width: 90.w,
              height: 45.h,
              padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),
              decoration: const BoxDecoration(color: Color(0xffF7CA36), borderRadius: BorderRadius.only(topLeft: Radius.circular(30), bottomLeft: Radius.circular(30), topRight: Radius.circular(0), bottomRight: Radius.circular(0))),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  if (controller.bookInfo['status'] == 2) ...[
                    Text(
                      '发起拼团',
                      style: setTextStyle(15, FontWeight.w500, Colors.white),
                    ),
                    Text(
                      controller.bookInfo['priceBookMaster'] > 0 ? '¥${controller.bookInfo['priceBookMaster'].toString()}' : '¥${controller.bookInfo['price'].toString().split(',')[0]}',
                      style: setTextStyle(15, FontWeight.w500, Colors.white),
                    ),
                  ] else ...[
                    const Text(
                      '加入购物车',
                      style: TextStyle(color: Colors.white, fontSize: 15), // 按钮文本样式
                    ),
                  ],
                ],
              ),
            ),
            onClick: () {
              if (controller.bookInfo['status'] == 2) {
                controller.createTeamWork();
              } else {
                controller.addCar();
              }
            },
          ),
          // 右边按钮
          SizedBox(
            // width: 90.w,
            height: 45.h,
            child: ElevatedButton(
              onPressed: () {
                controller.normalPreOrder();
              },
              style: ElevatedButton.styleFrom(
                padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),
                backgroundColor: Tools.fromHex('#F83F2D'), // 设置背景色
                shape: const RoundedRectangleBorder(
                  borderRadius: BorderRadius.only(
                    topRight: Radius.circular(30),
                    bottomRight: Radius.circular(30),
                  ),
                ),
                minimumSize: Size(0, 40.h), // 设置按钮的高度
              ),
              child: const Text(
                '单独购买',
                style: TextStyle(color: Colors.white, fontSize: 15), // 按钮文本样式
              ),
            ),
          ),
        ],
      ),
    );
  }

  // 砍价
  Widget _bottomBuyStyleHaggle(GoodsDetailController controller) {
    return Expanded(
      child: SizedBox(
        height: 80.h,
        child: Row(
          children: [
            Expanded(
              child: ElevatedButton(
                onPressed: () {
                  controller.jumpBargainingDetail();
                },
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 0),
                  backgroundColor: Tools.fromHex('#F7CA36'), // 去除默认背景色
                  shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.only(topLeft: Radius.circular(30), bottomLeft: Radius.circular(30)),
                  ), // 按钮圆角
                ),
                child: const Text(
                  '发起砍价',
                  style: TextStyle(color: Colors.white, fontSize: 15), // 按钮文本样式
                ),
              ),
            ),
            Expanded(
              child: ElevatedButton(
                onPressed: () {
                  controller.jumpFillOrder();
                },
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 0),
                  backgroundColor: Tools.fromHex('#F83F2D'), // 去除默认背景色
                  shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.only(
                      topRight: Radius.circular(30),
                      bottomRight: Radius.circular(30),
                    ),
                  ),
                ),
                child: const Text(
                  '单独购买',
                  style: TextStyle(color: Colors.white, fontSize: 15), // 按钮文本样式
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 秒杀
  Widget _bottomBuyStyleSeckillInfo(GoodsDetailController controller) {
    return Expanded(
      child: SizedBox(
        child: ElevatedButton(
          onPressed: () {
            controller.jumpFillOrder();
          },
          style: ElevatedButton.styleFrom(
            backgroundColor: Tools.fromHex('#F83F2D'), // 去除默认背景色
            shape: const RoundedRectangleBorder(
              borderRadius: BorderRadius.only(
                topRight: Radius.circular(30),
                bottomRight: Radius.circular(30),
                topLeft: Radius.circular(30),
                bottomLeft: Radius.circular(30),
              ),
            ),
          ),
          child: const Text(
            '立即购买',
            style: TextStyle(color: Colors.white, fontSize: 15), // 按钮文本样式
          ),
        ),
      ),
    );
  }

  // 预售
  Widget _bottomBuyStylePreSale(GoodsDetailController controller) {
    return Expanded(
      child: SizedBox(
          // 预售类型 1-全款预售 2-定金预售
          child: controller.preSaleInfo['presaleType'] == 2
              ? BaseInteractive(
                  childWidget: Container(
                      margin: EdgeInsets.symmetric(vertical: 8.h),
                      padding: EdgeInsets.symmetric(vertical: 8.h),
                      decoration: const BoxDecoration(
                        color: Color(0xffF7CA36),
                        borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(30),
                          bottomLeft: Radius.circular(30),
                          topRight: Radius.circular(30),
                          bottomRight: Radius.circular(30),
                        ),
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        mainAxisSize: MainAxisSize.max,
                        children: [
                          Text(
                            '支付定金',
                            style: setTextStyle(15, FontWeight.normal, Colors.white),
                          ),
                          const SizedBox(width: 5),
                          Text(
                            '¥${controller.preSaleInfo['deposit'].toString().split(',')[0]}',
                            style: setTextStyle(15, FontWeight.normal, Colors.white),
                          ),
                        ],
                      )),
                  onClick: () {
                    controller.jumpFillOrder();
                  },
                )
              : ElevatedButton(
                  onPressed: () {
                    controller.jumpFillOrder();
                  },
                  style: ElevatedButton.styleFrom(
                    padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15),
                    backgroundColor: Tools.fromHex('#F83F2D'), // 去除默认背景色
                    shape: const RoundedRectangleBorder(
                      borderRadius: BorderRadius.only(
                        topRight: Radius.circular(30),
                        bottomRight: Radius.circular(30),
                        topLeft: Radius.circular(30),
                        bottomLeft: Radius.circular(30),
                      ),
                    ),
                  ),
                  child: const Text(
                    '立即抢购',
                    style: TextStyle(color: Colors.white, fontSize: 12), // 按钮文本样式
                  ),
                )),
    );
  }

  // 卡券订单
  Widget _bottomBuyStyleCardCoupon(GoodsDetailController controller) {
    return Expanded(
      child: BaseInteractive(
        childWidget: Container(
            height: 40.h,
            decoration: BoxDecoration(color: Tools.fromHex('#F83F2D'), borderRadius: const BorderRadius.only(topLeft: Radius.circular(30), bottomLeft: Radius.circular(30), topRight: Radius.circular(30), bottomRight: Radius.circular(30))),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  '立即购买',
                  style: setTextStyle(12, FontWeight.w500, Colors.white),
                ),
              ],
            )),
        onClick: () {
          controller.jumpFillOrder();
        },
      ),
    );
  }
}
